home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / AMReminder / CAMReminderData.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  2.5 KB  |  158 lines  |  [TEXT/CWIE]

  1. // CAMReminderData.cp -- document data
  2.  
  3. #include "CAMReminderData.h"
  4.  
  5. #include <LFileStream.h>
  6. #include "DDocData.h"
  7.  
  8. //----------
  9. // initialize application data
  10.  
  11. void    CAMReminderData::InitAppData()
  12. {
  13. }
  14.  
  15. //----------
  16. CAMReminderData::CAMReminderData()
  17.     : LBroadcaster()
  18. {
  19.     mDocData = nil;
  20.     mFile = nil;
  21.     mDirty = false;
  22. }
  23.  
  24. //----------
  25. CAMReminderData::~CAMReminderData()
  26. {
  27.     if (mDocData != nil) {
  28.         delete mDocData;
  29.     }
  30.     CloseFile();
  31. }
  32.  
  33. //----------
  34. void    CAMReminderData::NewData ()
  35. {
  36.     InitDocData();
  37. }
  38.  
  39. //----------
  40. void    CAMReminderData::OpenData (
  41.     FSSpec*        inMacFSSpec)
  42. {
  43.     InitDocData();
  44.     mFile = OpenFile (inMacFSSpec);
  45.     ReadData();
  46. }
  47.  
  48. //----------
  49. void    CAMReminderData::InitDocData ()
  50. {
  51.     mDocData = new DDocData;
  52. }
  53.  
  54. //----------
  55. Boolean    CAMReminderData::IsDirty ()
  56. {
  57.     return mDirty;
  58. }
  59.  
  60. //----------
  61. void    CAMReminderData::DoSave ()
  62. {
  63.     WriteData (mFile);
  64. }
  65.  
  66. //----------
  67. void    CAMReminderData::DoSaveAs (
  68.     FSSpec*        inMacFSSpec)
  69. {
  70.     LFileStream*    file;
  71.  
  72.     file = CreateFile (inMacFSSpec);
  73.     if (file != nil) {
  74.         WriteData (file);
  75.         CloseFile ();    // old file
  76.         mFile = file;
  77.     }
  78. }
  79.  
  80. //----------
  81. void    CAMReminderData::DoRevert ()
  82. {
  83.     DisposeData();
  84.     if (mFile != nil) {
  85.         ReadData();
  86.     }
  87. }
  88.  
  89. //----------
  90. void    CAMReminderData::CloseFile ()
  91. {
  92.     if (mFile != nil) {
  93.         delete mFile;
  94.         mFile = nil;
  95.     }
  96. }
  97.  
  98. //----------
  99. // CreateFile is called in two situations:
  100. // 1. To Save a new untitled document
  101. // 2. To SaveAs to a new file
  102.  
  103. LFileStream*    CAMReminderData::CreateFile (
  104.     FSSpec*        inMacFSSpec)
  105. {
  106.     LFileStream*    file = new LFileStream (*inMacFSSpec);
  107.  
  108.     file->CreateNewDataFile (kSignature, kFileType);
  109.     file->OpenDataFork (fsRdWrPerm);
  110.  
  111.     return file;
  112. }
  113.  
  114. //----------
  115. LFileStream*    CAMReminderData::OpenFile (
  116.     FSSpec*        inMacFSSpec)
  117. {
  118.     LFileStream*    file = new LFileStream (*inMacFSSpec);
  119.  
  120.     file->OpenDataFork (fsRdWrPerm);
  121.  
  122.     return file;
  123. }
  124.  
  125. // The next few methods are for transferring data between the
  126. // data file and your internal data structures, and for disposing
  127. // your data structures. They are called by Open, Close, etc.
  128. // Replace their bodies with whatever is suitable for your application
  129.  
  130. //----------
  131. void    CAMReminderData::DisposeData ()
  132. {
  133.     // delete your data structures
  134.  
  135.     mDirty = false;
  136. }
  137.  
  138. //----------
  139. void    CAMReminderData::ReadData ()
  140. {
  141.     mDirty = false;
  142.  
  143.     mDocData->ReadFromFile (mFile);
  144. }
  145.  
  146. //----------
  147. // WriteData is called in two situations:
  148. // 1. To Save the current document
  149. // 2. To SaveAs to a new file
  150.  
  151. void    CAMReminderData::WriteData (
  152.     LFileStream*        file)
  153. {
  154.     mDirty = false;
  155.  
  156.     mDocData->WriteToFile (file);
  157. }
  158.